//
// Created by PC on 2024/4/19.
//

#include <iostream>
#include <vector>


struct Node
{
    int v;
    Node *next;
};

struct DNode {
    int v;
    DNode * pre;
    DNode * next;
};
/// 打印带头结点的单链表
/// \param h
void printLinkedList(Node *h)
{
    Node *cur = h->next;
    while (cur)
    {
        std::cout << cur->v << ' ';
        cur = cur->next;
    }
    std::cout << std::endl;
}

/// 建立带头结点的单链表
/// \param v
/// \return
Node * build(std::vector<int> v)
{
    Node *head = new Node();
    Node *cur = head;
    for (int i = 0; i < v.size(); ++i)
    {
//        cur->next=new Node{l[i], nullptr};
        cur->next = new Node();
        cur->next->v = v[i];
        cur = cur->next;
    }
    return head;
}

// 创建双链表 尾插法 正序
DNode * Dbuild(std::vector<int> v)
{
    DNode *h=new DNode();
    DNode *cur = h;
    for (int i = 0; i < v.size(); ++i)
    {
        DNode *t = new DNode{v[i],cur,nullptr};
        cur->next=t;
        cur=cur->next;
    }
    return h;
}

// 打印双链表
void printDLinkedList(DNode *h)
{
    DNode * cur=h->next;
    while(cur)
    {
        std::cout<<cur->v<<' ';
        cur=cur->next;
    }
    std::cout<<std::endl;
}